<template>
  <div class="app-container">
    <el-form :model="form" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="8">
          <el-form-item label="姓名">
            <el-input type="text" v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="任务名">
            <el-input type="text" v-model="form.taskName" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="电话">
            <el-input type="text" v-model="form.tel" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="finishNuclein" >完成核酸</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>


  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('年龄不能为空'));
      }

    };
    return {
      user: '',
      task: '',
      form: {
        taskName: "",
        taskId: "",
        name: "",
        id: "",
        tel: ""
      }

    };
  },
  methods: {
    getQueryResult() {
      request({
        url: '/hslog?user='+this.user+'&task='+this.task,
        method: 'get',
      }).then(res=>{
        this.form = res;
      })
    },
    finishNuclein() {
      request({
        url: '/nuclein/householdNucleinTask/finishNuclein',
        method: 'post',
        data: this.form,
      }).then(res=>{
        this.form = res;
        alert("确认成功！")
      })
    }


  },
  mounted() {
    var url = window.location.href
    let paramStr = url.substring(url.indexOf("?")+1);//code=xxx&state=1
    let paramArr = paramStr.split("&");//[code=xxx,state=1]
    let paramObj = {};
    for(let i = 0;i<paramArr.length;i++){
      let paramTemp = paramArr[i];//code=xxx
      let paramName = paramTemp.split("=")[0];//code
      let paramValue= paramTemp.split("=")[1];//xxx
      paramObj[paramName] = paramValue;//{code:xxx,state:1}
    }
    this.user = paramObj.user
    this.task = paramObj.task
    this.getQueryResult();

  }
}
</script>
